home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk1.zip / LST10-12.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  2KB  |  62 lines

  1. ;
  2. ; *** Listing 10-12 ***
  3. ;
  4. ; Clears a 1000-byte block of memory via BlockClear64,
  5. ; which handles blocks between 1 and 64K bytes in
  6. ; length. BlockClear64 gains the ability to handle
  7. ; 64K blocks by using STOSW rather than STOSB to
  8. ; the greatest possible extent, getting a performance
  9. ; boost in the process.
  10. ;
  11.     jmp    Skip
  12. ;
  13. ARRAY_LENGTH    equ    1000
  14. ByteArray    db    ARRAY_LENGTH dup (?)
  15. ;
  16. ; Clears a block of memory CX bytes in length. A value
  17. ; of 0 means "clear 64K bytes," so the maximum length
  18. ; that can be cleared is 64K bytes and the minimum length
  19. ; is 1 byte.
  20. ;
  21. ; Input:
  22. ;    CX = number of bytes to clear
  23. ;    ES:DI = start of block to clear
  24. ;
  25. ; Output:
  26. ;    none
  27. ;
  28. ; Registers altered: AX, CX, DI
  29. ;
  30. ; Direction flag cleared
  31. ;
  32. BlockClear64:
  33.     sub    ax,ax    ;fill with zero a word at a time
  34.     stc        ;assume the count is zero-setting
  35.             ; the Carry flag will give us 8000h
  36.             ; after the RCR
  37.     jcxz    DoClear    ;the count is zero
  38.     clc        ;it's not zero
  39. DoClear:
  40.     rcr    cx,1    ;divide by 2, copying the odd-byte
  41.             ; status to the Carry flag and
  42.             ; shifting a 1 into bit 15 if and
  43.             ; only if the count is zero
  44.     cld        ;make STOSW move DI up
  45.     rep    stosw    ;clear the block
  46.     jnc    ClearDone
  47.             ;the Carry status is still left over
  48.             ; from the RCR. If we had an even #
  49.             ; of bytes, we're done
  50.     stosb        ;clear the odd byte
  51. ClearDone:
  52.     ret
  53. ;
  54. Skip:
  55.     call    ZTimerOn
  56.     mov    di,seg ByteArray
  57.     mov    es,di    ;point ES:DI to the array to clear
  58.     mov    di,offset ByteArray
  59.     mov    cx,ARRAY_LENGTH    ;# of bytes to clear
  60.     call    BlockClear64    ;clear the array
  61.     call    ZTimerOff
  62.